create or replace view vac_app_templates_4_1 as
with tmpl as
(
select
  workspace,
  workspace_display_name,
  application_id,
  application_name,
  theme_number,
  template_type,
  template_name,
  to_char(reference_count) reference_count,
  last_updated_on,
  last_updated_by,
  is_subscribed,
  is_default,
  template_id
from APEX_APPLICATION_TEMPLATES app_t
)
select
  workspace,
  workspace_display_name,
  application_id,
  application_name,
  theme_number,
  template_name,
  last_updated_on,
  last_updated_by,
  template_id,
  u_name,
  u_value,
  'APEX_APPLICATION_TEMPLATES' src_view_name
from tmpl
 UNPIVOT INCLUDE NULLS
 ( u_value
   FOR    u_name
   IN
   (
    template_type,
    reference_count,
    is_default
   )
 );

